package com.zql.LeetCode;

/**
 * Created By ShuHua on 2021/8/22.
 */
public class CorpFlightBookings_1109 {
    public static int[] corpFlightBookings(int[][] bookings, int n) {

        int[] diff = new int[n];
        int[] res = new int[n];
        for(int i=0;i<bookings.length;i++){
            int first =bookings[i][0];
            int end = bookings[i][1];
            int count = bookings[i][2];
            diff[first-1] += count;
            //这里需要判断end是否小于航班数，如果等于则会报数组越界异常
            if(end<n) diff[end] -=count;
        }
        res[0] =  diff[0];
        for(int i=1;i<n;i++){
            res[i] = res[i-1]+diff[i];
        }
        return res;
    }

}
